--prelude = "data metalist = metalist a metalist | metaemptylist\n\n"
tanslateFile filename =
  do
    preludeFullName  <- getDataFileName "doc/prelude.phs"
    preludehFullName <- getDataFileName "c++_runtime/prelude.h"
    putStrLn $ "Getting prelude from: "++preludeFullName
    preludeHandle <- openSecureFile preludeFullName
    preludehHandle <- openSecureFile preludehFullName
    prelude  <- hGetContents preludeHandle
    preludeh <- hGetContents preludehHandle
    fromHandle  <- openSecureFile filename
    -- Open the filenames, .h and .lambda (for debuging purpose)
    lambdaOutHandle <- openOutputFile (filename++".lambda")
    preludehOutHandle <- openOutputFile "prelude.h"
    outHandle <- openOutputFile (filename++".h")
    -- put the pragma once on the .h file
    hPutStr outHandle (makePragmaOnce filename)	
    -- get the phs program	 		
    fileContent <- hGetContents fromHandle
    -- print the file contene in .lambda and .h files
    hPutStr lambdaOutHandle ("/*\npHaskell Code: \n\n"++fileContent++"\n*/\n\n\n")
    hPutStr outHandle ("/*\npHaskell Code: \n\n"++fileContent++"\n*/\n\n\n")
    -- start fase 1
    fase1Result <- return (makeFase1 (prelude++"\n"++fileContent))
    -- save the output on the .lambda file, and close the file
    hPutStr lambdaOutHandle (lambdaPretyPrinterProgram fase1Result)
    hClose lambdaOutHandle
    -- save the fase 1 output as comment in .h file
    hPutStr outHandle ("/*\nLambda Abstraction: \n\n"++(lambdaPretyPrinterProgram fase1Result)++"\n*/\n\n\n")
    -- start the fase 1
    fase2Result <-  return (makeFase2 fase1Result)
    -- start the generatrix fase
    generatrixes <- return (generatrixRender (prelude++"\n"++fileContent))
    --putStr fileContent
    putStr (lambdaPretyPrinterProgram fase1Result)
    putStr fase2Result
    -- save the fase 2 result and generatrix result in .h file
    hPutStr outHandle fase2Result
    hPutStr outHandle ("\n/* GENERATRIX SECTION */\n")
    hPutStr outHandle generatrixes
    hPutStr outHandle ("\n#endif\n")
    hPutStr preludehOutHandle preludeh
    -- close the opened file handlers
    hClose fromHandle
    hClose outHandle
    hClose preludeHandle
    hClose preludehOutHandle
    putStr "\n\nDone."
